package com.dhy.springboot01thymeleaf.config;

import com.dhy.springboot01thymeleaf.component.LoginHandlerInterceptor;
import com.dhy.springboot01thymeleaf.component.MyLocaleResolver;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.*;

//@EnableWebMvc
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {






//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/**")
//                .addResourceLocations("classpath:/")
//                .addResourceLocations("classpath:/public/")
//                .addResourceLocations("classpath:/static/")
//                .addResourceLocations("classpath:/resources/")
//                .addResourceLocations("classpath:/META-INF/resources/");
//        registry.addResourceHandler("/webjars/**")
//                .addResourceLocations("classpath:/META-INF/resources/webjars/");
//    }

    //视图映射
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //配置跳转页面
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("success");
    }

    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")                                     //拦截哪些请求
                .excludePathPatterns("/index.html","/","/user/login");      //放行哪些请求
    }



}
